{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "45\n"
     ]
    }
   ],
   "source": [
    "i = ord(\"-\")\n",
    "print(f\"{i}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "def divide(x:int, y:int)->int:\n",
    "    if y > x:\n",
    "        return 0\n",
    "    if y == 1:\n",
    "        return x\n",
    "    q = divide(x, y + y)\n",
    "    q2 = q + q\n",
    "    q2y = q2 * y\n",
    "    if (x - q2y) < y:\n",
    "        return q2\n",
    "    else:\n",
    "        return q2 + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "16383\n"
     ]
    }
   ],
   "source": [
    "print(divide(32767,2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "def divide(x:int, y:int)->int:\n",
    "    lst:list[int] = []\n",
    "    while(y <= x):\n",
    "        lst.append(y)\n",
    "        y = 2 * y\n",
    "        pass\n",
    "    q = 0\n",
    "    q2y = 0\n",
    "    i = len(lst)-1\n",
    "    while(i >=0):\n",
    "        y = lst[i]\n",
    "        q2 = 2 * q\n",
    "        # q2y = q2 * y\n",
    "        # q2y = q2y + q2y\n",
    "        if (x - q2y) < y:\n",
    "            q = q2\n",
    "        else:\n",
    "            q = q2 + 1\n",
    "            q2y = q2y + y\n",
    "        i = i -1\n",
    "        pass\n",
    "    return q"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "24\n"
     ]
    }
   ],
   "source": [
    "print(divide(24, 1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "def sqrt(x:int):\n",
    "    n = 0;\n",
    "    val = 0;\n",
    "    while(val < x):\n",
    "        n = n + 1\n",
    "        val = pow(2,n)\n",
    "        \n",
    "    y = 0\n",
    "    print(f\"n={n}\")\n",
    "    max = (n / 2) - 1\n",
    "    i = max\n",
    "    while i >= 0:\n",
    "        if pow(y + pow(2, i), 2) <= x:\n",
    "            y = y + pow(2,i)\n",
    "        i = i - 1\n",
    "    return y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "def sqrt(x:int):\n",
    "    low = 1\n",
    "    high = x\n",
    "    while low <= high:\n",
    "        mid = int(low + (high-low)/2)\n",
    "        s = int(x / mid)\n",
    "        if abs(mid - s) <= 1:\n",
    "            if mid < s:\n",
    "                return mid\n",
    "            else:\n",
    "                return s\n",
    "        elif mid > s:\n",
    "            high = mid\n",
    "        else:\n",
    "            low = mid\n",
    "        pass\n",
    "    return high"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "n=15\n",
      "178.19090885901\n"
     ]
    }
   ],
   "source": [
    "print(sqrt(32000))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "100.0\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "print(math.sqrt(10000))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
